﻿namespace USElections.Calendar.Model
{
    using System;
    using System.Linq;
    using Telerik.Windows.Controls;
    using USElections.Model;

    /// <summary>
    /// ElectionsAppointmentSource class.
    /// </summary>
    public class ElectionsAppointmentSource : AppointmentSource
    {
        #region Constructor
        /// <summary>
        /// Initializes a new instance of the ElectionsAppointmentSource class.
        /// </summary>
        public ElectionsAppointmentSource()
        {
        }
        #endregion

        #region Public methods
        /// <summary>
        /// Returns the appointment data for a specific period.
        /// </summary>
        /// <param name="startDate">The parameter is not used.</param>
        /// <param name="endDate">The parameter is not used.</param>
        public override void FetchData(DateTime startDate, DateTime endDate)
        {
            this.AllAppointments.Clear();

            foreach (var item in Data.Instance.CalendarItems.Where(x=>x.StartDate >= startDate && x.EndDate <= endDate))
            {
                this.AllAppointments.Add(new ElectionsAppointment()
                {
                    Id = item.Id,
                    StartDate = item.StartDate,
                    EndDate = item.EndDate,
                    Details = item.Details,
                    Subject = item.Subject,
                });
            }

            this.OnDataLoaded();
        }
        #endregion
    }
}
